// pages/question/question.js
let utils = require("../../utils/utils.js");
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeNames: 1
    , questionListUrl: '/question/list'
    , questions: []
  },
  question: function (e) {
    let index = e.currentTarget.dataset.index;
    let that = this;
    that.data.questions.map(function (val, key) {
      if (index != key) {
        val.status = false;
      };
    });
    that.data.questions[index].status = !that.data.questions[index].status;
    that.setData({
      questions: that.data.questions,
    })
  },
  getQuestionList: function () {
    let that = this;
    let _data = {
      url: that.data.questionListUrl,
      methods: 'post',
      data: ''
    };
    utils.request.call(_data, (res) => {
      console.log(res);
      that.data.questions = res.data.data;
      that.data.questions.map(function (val, key) {
        val.status = false;
        that.data.questions[0].status = true;
      });
      that.setData({
        questions: that.data.questions,
      })
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that=this;
    let userInfo = wx.getStorageSync('userInfo');
    that.getQuestionList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})